package xy.mybatis.plus.dao;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import xy.mybatis.plus.entity.User;
import xy.mybatis.plus.vo.UserDeptVo;

import java.sql.Wrapper;

/**
 * (User)表数据库访问层
 *
 * @author halo-king
 * @since 2023-06-02 16:17:00
 */
@Mapper
public interface UserDao extends BaseMapper<User> {

    @Select(" select * from user ")
    IPage<User> queryUserByPageAnnotation(Page page);

    @Select(" select * from user ${ew.customSqlSegment} ")
    IPage<User> queryUserByPageAnnotationAndParams(Page page,@Param(Constants.WRAPPER) QueryWrapper<User> ew);

    IPage<User> queryUserByPage(Page page);

    IPage<User> queryUserMutlParamsByPage(Page page, @Param(Constants.WRAPPER) QueryWrapper<User> ew);

    // 多表联合查询

    @Select("  select t1.*,t2.dept_name from user t1 left join dept t2 on t1.dept_id = t2.id ")
    IPage<UserDeptVo> queryUserDeptByPageAnnotation(Page page);

    @Select("  select t1.*,t2.dept_name from user t1 left join dept t2 on t1.dept_id = t2.id  ${ew.customSqlSegment} ")
    IPage<UserDeptVo> queryUserDeptByPageAnnotationAndParams(Page page,@Param(Constants.WRAPPER) QueryWrapper<User> ew);

    IPage<UserDeptVo> queryUserDeptByPage(Page page);

    IPage<UserDeptVo> queryUserDeptMutlParamsByPage(Page page, @Param(Constants.WRAPPER) QueryWrapper<User> ew);
}
